import { Component, OnInit } from '@angular/core';
import { Hero } from './app.hero';
import { HeroService } from './hero.service';

@Component({
    selector: 'app-heroes',
    templateUrl: './heroes.component.html',
    styleUrls: ['./app.component.css']
})

export class HerosComponent implements OnInit {

    chero: Hero;
    heroes: Hero[];

    constructor(private heroService: HeroService) {

    }

    onSelect(h: Hero) {
        this.chero = h;
    }

    ngOnInit(): void {
        this.heroService.getHeroes().then((heroes) => {
            this.heroes = heroes;
        });
    }

    add(name): void {
        this.heroService.addHero(name).then(() => { });
    }

    delete(hero: Hero): void {
        this.heroService.removeHero(hero.id).then(() => { });
    }

}







